package com.example.tests;

import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.*;

import java.util.Random;
import org.testng.annotations.Test;
import com.example.utils.SortedListOf;

public class ContactModificationTests extends TestBase {
	@Test(dataProvider = "randomValidContactGenerator")
	public void modifySomeContact(ContactData contact){
		//save old contacts
		SortedListOf<ContactData> oldContacts = app.getContactHelper().getContacts();
		
		int rndIndex = new Random().nextInt(oldContacts.size());
		
		//action
		app.getContactHelper().modifyContact(rndIndex, contact);
		
		//save new contacts
		SortedListOf<ContactData> newContacts = app.getContactHelper().getContacts();
		
		// assertion
		assertThat(newContacts, equalTo(oldContacts.without(rndIndex).withAdded(contact)));
	}
	
	@Test(dataProvider = "invalidContactGenerator")
	public void unsuccessfullModifySomeContact(ContactData contact){
		//save old contacts
		SortedListOf<ContactData> oldContacts = app.getContactHelper().getContacts();
		
		int rndIndex = new Random().nextInt(oldContacts.size());
		
		//action
		app.getContactHelper().modifyContact(rndIndex, contact);
		
		//save new contacts
		SortedListOf<ContactData> newContacts = app.getContactHelper().getContacts();
		
		// assertion
		assertThat(newContacts, equalTo(oldContacts));	
	}
}
